package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.job.OaLearnListener;
import com.cheer.service.AuthService;
import com.cheer.service.OaLearnService;
import com.cheer.vo.OaLearnFrontInfoVO;
import com.cheer.vo.OaLearnFrontVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/learn")
public class OaLearnController {

    @Autowired
    private OaLearnService oaLearnService;

    @Autowired
    private AuthService authService;

    @ApiOperation("查看主题团课")
    @GetMapping("/home")
    public Result<OaLearnFrontVO> home(HttpSession session) {
        OaLearnListener.removeTask(authService.getOpenid(session));

        return Result.success(oaLearnService.listFront());
    }

    @ApiOperation("查看每一季的学习")
    @GetMapping("/list/info")
    public Result<List<OaLearnFrontInfoVO>> list(@RequestParam Integer pid, HttpSession session) {
        OaLearnListener.removeTask(authService.getOpenid(session));

        return Result.success(oaLearnService.listByPid(pid));
    }

    @ApiOperation("进入学习")
    @GetMapping("/enter")
    public Result<String> url(@RequestParam Integer id, HttpSession session) {
        return Result.success(oaLearnService.enter(id, authService.getUserId(session), authService.getOpenid(session)));
    }

}
